% parse an msb file, and return the result in a structure
% of form result.name, each holding a value in string format.
%
function [result, err] = msb_parse(filename)
result = [];
err = 0;

msbpath = 'f:\MSB\';
startpath = sprintf('%s\\%s', 'f:\MSB', '*.msb');
% disp(startpath);
if(isempty(filename))
   [filename, path] = uigetfile(startpath, 'Open Data Files');
end

if(filename == 0)
   disp(sprintf('unable to access file? %s - %s', path, filename));
   err = 1;
   return;
end
truefile = strcat(msbpath, filename);
fid=fopen(truefile, 'rt');
disp(sprintf('Parsing %s', filename))
while (~feof(fid))
   inline = char(fgetl(fid));
   if(isempty(inline) | inline <= 0 | feof(fid) | (length(inline) < 1))
      fclose(fid);
      return;
   end
   if~(strcmp(inline(1), ';'))
      [temp, a] = parse_line(inline);
   if(~isempty(a))
      name = (string_fromline(temp, a, 1));
      value = char(string_fromline(temp, a, 2));
      newvalue=[];
      j = 1;
      for i=1:length(value)
         if(value(i) ~= '"') 
            newvalue(j)=value(i);
            j=j+1;
         end
      end
      newvalue = deblank(char(newvalue));
      % disp(sprintf('name: %s (%d)  newvalue: %s (%d) newvalue(1) = %d', name, length(name), newvalue, length(newvalue), newvalue(1)))
      if(~isempty(name) & ~isempty(newvalue) & ~strcmp(name(1), '.') & newvalue(1) > 32)
         arg=sprintf('result.%s',deblank(char(name)));
         eval([char(arg), '=newvalue;']);
      end
   end
end
end
fclose(fid);
return;






